package io.renren.util.weichuang;

import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.renren.util.RandomUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class TestPdd {

    public static void main(String[] args) throws ParseException, IOException {

        String priKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAh2dp57oVSPvXOSq6RTZbdB0j3nkJgqDr2tkt6XgwKY+ZoX8hYURZzV86aui2XJ/YXOwI99z+bAktGDQjjiaU409k9scBkgOwDcsK+u5E6KOzClNgmMc9MQ1V14EiV8ckLIPpLNqRy+zeHZZrlWunHl9yunlUliDUw6JgQ6sx+vszkMLN1ZPM6KcAG6kdhWvvgPkzEkm5CE9cMN8S1Q8oTD+WR9okYIhx1O24MWt7k/HkQeEVOUPI6YoqsxD2+wKj6A9/J8HzmF/k1f97wJwe9caKpAoPw3P3UDcU1Zfd7H2TMhnHR4ipdPilkGwZqX9NYvC/oGM/ug34JI9O4ZM2FwIDAQAB";
        String orderUrl = "http://120.195.6.164:81/qfpay.open/pdd/friendPay";

        String outTradeNO = RandomUtils.generateLowerString(32);
        String appId = "20200111105912146459";
        String userAgent = "AlipayClient";
        String notifyUrl = "http://127.0.0.1:8090/api/xwcallbac";
        String money = "42";

        Map<String, String> map = new HashMap<String, String>();
        map.put("outTradeNo", outTradeNO);
        map.put("money", money);
        map.put("appId", appId);
        map.put("userAgent", userAgent);
        map.put("notifyUrl", notifyUrl);

        String sign = null;
        try {
            sign = RSA2Util.rsaSign(map, priKey);
        } catch (Exception e) {
            e.printStackTrace();
        }
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("outTradeNo", outTradeNO));
        params.add(new BasicNameValuePair("money", money));
        params.add(new BasicNameValuePair("appId", appId));
        params.add(new BasicNameValuePair("userAgent", userAgent));
        params.add(new BasicNameValuePair("notifyUrl", notifyUrl));
        params.add(new BasicNameValuePair("sign", sign));
        System.out.println(HttpReq.httpRequest(orderUrl, params));
    }

}
